package org.neuedu.servlet;

import org.neuedu.bean.User;
import org.neuedu.service.UserService;
import org.neuedu.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "UserSetServlet", urlPatterns = "/set")
public class UserSetServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        String email = request.getParameter("email");
        String username = request.getParameter("username");
        String sex = request.getParameter("sex");
        String city = request.getParameter("city");
        String sign = request.getParameter("sign");
        User user = (User) session.getAttribute("fly_user");
        Integer id = user.getId();
        User u = new User();
        boolean y = false;
        if (Integer.valueOf(sex) == 0) {
            y = false;
        } else if (Integer.valueOf(sex) == 1) {
            y = true;
        }
        u.setEmail(email);
        u.setNickName(username);
        u.setGender(y);
        u.setCity(city);
        u.setSign(sign);
        u.setId(id);
        UserService service = new UserServiceImpl();
        service.updateset(u);
        user.setEmail(email);
        user.setNickName(username);
        user.setGender(y);
        user.setCity(city);
        user.setSign(sign);
        request.getRequestDispatcher("/user/set").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
